#include "ControlUtility.h"

namespace MiniWindow
{
	DWORD ControlUtility::ModifyBit(DWORD original, DWORD add, DWORD remove)
	{
		if (0 != add)
		{
			original = add | original;
		}
		if (0 != remove)
		{
			original = original & (~remove);
		}
		return original;
	}
	bool ControlUtility::ModifyStyle(HWND handle, DWORD addStyle, DWORD removeStyle)
	{
		if (null == handle)
		{
			return false;
		}
		LONG style = GetWindowLong(handle, GWL_STYLE);
		LONG styleTemp = style;
		if (0 != addStyle)
		{
			styleTemp = style | addStyle;
		}
		if (0 != removeStyle)
		{
			styleTemp = style & (~removeStyle);
		}
		if (style != styleTemp)
		{
			return (0 != SetWindowLong(handle, GWL_STYLE, styleTemp));
		}
		return false;
	}
	bool ControlUtility::ModifyStyleEx(HWND handle, DWORD addStyle, DWORD removeStyle)
	{
		if (null == handle)
		{
			return false;
		}
		LONG style = GetWindowLong(handle, GWL_EXSTYLE);
		LONG styleTemp = style;
		if (0 != addStyle)
		{
			styleTemp = style | addStyle;
		}
		if (0 != removeStyle)
		{
			styleTemp = style & (~removeStyle);
		}
		if (style != styleTemp)
		{
			return (0 != SetWindowLong(handle, GWL_EXSTYLE, styleTemp));
		}
		return false;
	}

	bool ControlUtility::ContainStyle(HWND handle, DWORD style)
	{
		LONG nstyle = GetWindowLong(handle, GWL_STYLE);
		return ((nstyle | style) == nstyle);
	}
	bool ControlUtility::ContainStyleEx(HWND handle, DWORD style)
	{
		LONG nstyle = GetWindowLong(handle, GWL_EXSTYLE);
		return ((nstyle | style) == nstyle);
	}
}